#include "startset.h"
#include "ui_startset.h"
#include "keyboard.h"
#include <QFileDialog>
#define COLUMN_SPACING 20
Startset::Startset(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Startset)
{
      SetMainBacklight();
      ui->setupUi(this);
      ycapi = new Ycapi();

     ui->lineEditSetStartPathParam->installEventFilter(this);

    char buf[100]={0};
    ycapi->GetAutoStartPath(buf);
    ui->lineEditDisStartPath->setText(QString(buf));
    ui->lineEditAutoStartDir->setAttribute(Qt::WA_InputMethodEnabled,false);
    ui->lineEditSetStartPathParam->setAttribute(Qt::WA_InputMethodEnabled,false);
}
void Startset::SetMainBacklight()
{
QPalette bgpal = palette();
bgpal.setColor (QPalette::Background, QColor (0, 0 , 0, 255));
bgpal.setColor (QPalette::Foreground, QColor (255,0,0,255));
setPalette (bgpal);
}

Startset::~Startset()
{
    delete ui;
    delete ycapi;
}
bool  Startset::eventFilter(QObject *obj, QEvent *event)
{
    if(obj==ui->lineEditSetStartPathParam)
    {
        if(event->type()==QEvent::MouseButtonPress)
        {
           //QMessageBox::information(NULL,"Titel","dfdfd",QMessageBox::Yes,QMessageBox::Yes);
           KeyBoard mKeyBoard(InputNone,NULL);
           connect(&mKeyBoard,SIGNAL(setvalue(QString)),obj,SLOT(setText(QString)));
           mKeyBoard.exec();
        }
    }
    return QDialog::eventFilter(obj,event);
}
void Startset::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}



void Startset::on_pushButtonAutoStartDir_clicked()
{
    QString path=QFileDialog::getOpenFileName(this,tr("设置开机自启动程序"),"/autostart/.",tr("All Files (*)"));
    if(!path.isEmpty())
        ui->lineEditAutoStartDir->setText(path);
}

void Startset::on_pushButtonAutoStartApply_clicked()
{
    char str[512]={0};
    QString path=ui->lineEditAutoStartDir->text() + " -qws " +ui->lineEditSetStartPathParam->text();
    sprintf(str,"chmod -r 777 %s ",ui->lineEditAutoStartDir->text().toLatin1().data());
    //printf("xxxxx:%s\n",str);
    system(str);
    ycapi->SetAutoStartPath(path.toLatin1().data());
}


void Startset::on_close_clicked()
{
    this->close();
}
